% run this file to recreate Table 4 ("Model Estimation : Implication for the Kalman filter Gain")

% The Kalman filter gain is an important ingredient into how model-agents assess shocks. 
% Both types of shocks in the model (Oil-supply shocks and TFP shocks) have both a permanent and a transitory component. 
% When observing an oil-supply shock, say, economic agents therfore need to assess
% whether they think that shock is permanent or temporary and the Kalman
% filter gain expresses that assessment. The gain is a function of the
% underying parameters in the DGPs of both components.

comp = [0 1];
track = 0;

% Parameter Values of oil supply shocks, early 2000s
rhoe_p = 0.99999;   % serial correlation of persistent oil-supply shocks
sige_p =  0.0655*0.01; % std. deviation of innovations to those shocks
rhoe_t = 0.8158;   % serial correlation of transitory oil-supply shocks
sige_t = 0.01;    % std. deviation of innovations to those shocks

% Parameter Values of TFP shocks "early 2000s"
rhoz_p = 0.99999;   % serial correlation of persistent TFP shocks
sigz_p = 0.2707*0.3694*0.01; % std. deviation of innovations to those shocks
rhoz_t = 0.8466;   % serial correlation of transitory TFP shocks
sigz_t = 0.3694*0.01;    % std. deviation of innovations to those shocks


whatinfo = 2;
% whatinfo = 1 implies "complete information" solution as defined in the paper; whatinfo = 2 implies "learning" solution 
answinv = 1;
% answinv = 1 implies solution where oil inventoires are present  
answlearn = 1;
% answlearn = 1 indicates the usual learning solution. "answlearn" = 0 implies the learning solution used to construct Table 5 

param = [rhoe_p sige_p rhoe_t sige_t rhoz_p sigz_p rhoz_t sigz_t answinv whatinfo answlearn];

gainkeep = []; %this is not used here but in other programs

% set the table up
table = zeros(2,6);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1- Report the Kalmn filter gain for the "early 2000s" case

% Call the program that computes the s.s. and the linearization

sstate


%disp('Gain of the filter')
gain = P*H/(H'*P*H);
%disp(gain)
%disp(' ')
table(1,1) = gain(1,1);
table(2,1) = gain(2,1);
table(1,2) = gain(3,2);
table(2,2) = gain(4,2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2- Report the Kalmn filter gain for the "late 2000s" case

%Modify parameter values to those estimated for that case

% Parameter Values of oil supply shocks, "late 2000s" values
rhoe_p = 0.99999;   % serial correlation of persistent oil-supply shocks
sige_p = 0.2408*0.01; % std. deviation of innovations to those shocks
rhoe_t = 0.8294;   % serial correlation of transitory oil-supply shocks
sige_t = 0.01;    % std. deviation of innovations to those shocks
% Parameter Values of TFP shocks, "late 2000s" values
rhoz_p = 0.99999;   % serial correlation of persistent TFP shocks
sigz_p = 2.4926*0.2592*0.01; % std. deviation of innovations to those shocks
rhoz_t = 0.8463;   % serial correlation of transitory TFP shocks
sigz_t = 0.2592*0.01;    % std. deviation of innovations to those shocks

whatinfo = 2;
% whatinfo = 1 implies "complete information" solution as defined in the paper; whatinfo = 2 implies "learning" solution 
answinv = 1;
% answinv = 1 implies solution where oil inventoires are present  

param = [rhoe_p sige_p rhoe_t sige_t rhoz_p sigz_p rhoz_t sigz_t answinv whatinfo answlearn];




% Call the program that computes the s.s. and the linearization

sstate


%disp('Gain of the filter')
gain = P*H/(H'*P*H);
%disp(gain)
disp(' ')
table(1,3) = gain(1,1);
table(2,3) = gain(2,1);
table(1,4) = gain(3,2);
table(2,4) = gain(4,2);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 3- Report the Kalmn filter gain for the "mid 2010s" case

%Modify parameter values to those estimated for that case

% Parameter Values of oil supply shocks, "mid 2010s" values
rhoe_p = 0.99999;   % serial correlation of persistent oil-supply shocks
sige_p = 0.1344*0.01; % std. deviation of innovations to those shocks
rhoe_t = 0.6899;   % serial correlation of transitory oil-supply shocks
sige_t = 0.01;    % std. deviation of innovations to those shocks
% Parameter Values of TFP shocks, "mid 2010s" values
rhoz_p = 0.99999;   % serial correlation of persistent TFP shocks
sigz_p = 0.5624*0.6159*0.01; % std. deviation of innovations to those shocks
rhoz_t = 0.9322;   % serial correlation of transitory TFP shocks
sigz_t = 0.6159*0.01;    % std. deviation of innovations to those shocks


whatinfo = 2;
% whatinfo = 1 implies "complete information" solution as defined in the paper; whatinfo = 2 implies "learning" solution 
answinv = 1;
% answinv = 1 implies solution where oil inventoires are present  

param = [rhoe_p sige_p rhoe_t sige_t rhoz_p sigz_p rhoz_t sigz_t answinv whatinfo answlearn];



% Call the program that computes the s.s. and the linearization

sstate


%disp('Gain of the filter')
gain = P*H/(H'*P*H);
%disp(gain)
disp(' ')
table(1,5) = gain(1,1);
table(2,5) = gain(2,1);
table(1,6) = gain(3,2);
table(2,6) = gain(4,2);

%ready to display the table
disp('      ')
disp('Table 4')
disp(table)



